package com.bsoft.coordinatorlayouttest;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

/**
 * Created by 泅渡者
 * Created on 2017/10/18.
 */

public class ToolBarSimple extends AppCompatActivity {
    Toolbar toolbar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toolbar);
        toolbar = (Toolbar) findViewById(R.id.my_toolbar);
        toolbar.setTitle("标题");
        toolbar.setSubtitle("子标题");
        // 显示导航按钮
        toolbar.setNavigationIcon(R.drawable.icon_menu);

        setSupportActionBar(toolbar);
        // 显示应用的Logo
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setDisplayUseLogoEnabled(true);
        getSupportActionBar().setLogo(R.mipmap.ic_launcher);
        // 显示标题和子标题
        getSupportActionBar().setDisplayShowTitleEnabled(true);


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.drawer_view, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            default:
                Toast.makeText(ToolBarSimple.this, "菜单被点击", Toast.LENGTH_SHORT).show();
                item.setChecked(true);
                return super.onOptionsItemSelected(item);

        }
    }

}
